package com.wsjj.yjh;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class TransAggregation {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<WaterSensor> source = env.fromElements(
                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_1", 2L, 2),
                new WaterSensor("sensor_2", 2L, 2),
                new WaterSensor("sensor_3", 3L, 3)
        );


        KeyedStream<WaterSensor, String> waterSensorStringKeyedStream = source.keyBy(value -> value.id);

//        waterSensorStringKeyedStream.sum("vc").print();
//        waterSensorStringKeyedStream.max("vc").print();
        waterSensorStringKeyedStream.maxBy("vc").print();
        env.execute();
    }
}
